﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace community.LanFen
{
    public partial class PWD_modify : Form
    {
        public PWD_modify()
        {
            InitializeComponent();
        }

        private void PWD_modify_Load(object sender, EventArgs e)
        {

        }

        //取消
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //确定
        private void button1_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn =new SqlConnection (SQL.conStr ))
            {
                string txt = "select   count (*) as num  from T_BSE_EMPLOYEE where EMPID_CHR=@User_uid and PSW_CHR=@User_pwd";
                SqlCommand com = conn.CreateCommand ();
                com.CommandText = txt;
                com.Parameters.AddWithValue("@User_uid",uid.Text.Trim());
                com.Parameters.AddWithValue ("@User_pwd",dataBase.encode ( old_pwd .Text.Trim()));
                conn.Open();
                SqlDataReader rdr = com.ExecuteReader();
                int count = 0;
                while (rdr.Read())
                {
                    count  = Convert .ToInt32 ( rdr["num"]);

                }

                if ((new_pwd1.Text.Trim ()==new_pwd_2 .Text .Trim ())&&count ==1)
                {
                    com.CommandText = "update T_BSE_EMPLOYEE set PSW_CHR = @pwd where EMPID_CHR=@User_uid ";
                    com.Parameters.AddWithValue("@pwd",dataBase.encode ( new_pwd1.Text.Trim ()));
                    com.Parameters.AddWithValue("@User_uid", uid.Text.Trim());
                    int i =com.ExecuteNonQuery();
                    if (i == 1)
                    {
                        MessageBox.Show("密码修改成功！");

                    }
                    else
                    {
                        MessageBox.Show("账号或密码错误！");
                        return;
                    }
                    
                }


            }
        }

    }
}
